import 'dart:async';
import 'package:demo/event/event_setting.dart';
import 'package:demo/tools/tools_enum.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:get/get.dart';
import 'package:demo/views/base/base_controller.dart';
import 'package:demo/tools/tools_storage.dart';

class MineCityController extends BaseController {
  TextEditingController cityController = TextEditingController();
  String province = '';
  String city = '';

  // 获取详情
  void _onRefresh() {
    LocalUser localUser = ToolsStorage().local();
    onChanged(localUser.province, localUser.city);
  }

  // 提交
  Future<void> submit() async {
    // 通知
    EventSetting().handle(
      SettingModel(
        SettingType.mine,
        label: 'city',
        value: '$province&$city',
      ),
    );
    // 提醒
    EasyLoading.showToast('修改成功');
    // 返回
    Get.back();
  }

  // 提交
  void onChanged(String p, String c) {
    province = p;
    city = c;
    cityController.text = '$province $city';
  }

  @override
  void onInit() {
    super.onInit();
    _onRefresh();
  }

  @override
  void onClose() {
    cityController.dispose();
    super.onClose();
  }
}
